#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#include <stdio.h>
#include <stdlib.h>

#define N 128

typedef struct msg
{
    long msg_type;
    char msg_text[N];
}MSG;

#define MSGTEXT_SIZE (sizeof(MSG)-sizeof(long))


int main()
{
    key_t mykey = 0;
    if((mykey = ftok(".",100)) == -1)
    {
        perror("fail to ftok");
        exit(-1);
    }

    int ms = 0;
    if((ms = msgget(mykey,IPC_CREAT| 0666)) == -1)
    {
        perror("fail to msgget");
        exit(-1);
    }
    
    MSG mymsg_1 = {2,"hello"};
    MSG mymsg_2 = {1," world"};
    if(msgsnd(ms,&mymsg_1,MSGTEXT_SIZE,0) == -1)
    {
        perror("fail to msgsnd");
        exit(-1);
    }
    if(msgsnd(ms,&mymsg_2,MSGTEXT_SIZE,0) == -1)
    {
        perror("fail to msgsnd");
        exit(-1);
    }
    system("ipcs -q");
    return 0;
}